/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jforum.domain;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 *
 * @author Вадим
 */
public class Message extends Entity implements Comparable<Message>{

    private String text;
    private int parent_id;
    private Date cr_time;
    private User user;
    private int level;
    private String path;

    private SimpleDateFormat sdf=new SimpleDateFormat("dd MMMM yyyy, HH:mm");

    public Message(int id, int parent_id, String text, User user, long cr_time, String path ) {
        super.ID=id;
        this.parent_id=parent_id;
        this.text=text;
        this.user=user;
        this.cr_time=new Date(cr_time);
        this.path = path;
    }

    @Override
    public Map getPropertyMap() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getText() {
        return text;
    }

    public int getParent_id() {
        return parent_id;
    }

    public Date getCr_time() {
        return cr_time;
    }

    /**
     * Возвращает время в виде строки в понятном формате
     * @return
     */
    public String getTime() {
        return sdf.format(cr_time);
    }

    public User getUser() {
        return user;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int compareTo(Message o) {
        int i = this.path.compareTo(o.path);
        if (this.level == o.level) {
            return this.cr_time.compareTo(o.cr_time);
        }
        return i;
    }

}
